--- title: test layout: post --- scratch_notebook.knit

Grab fridays data

library(RPostgreSQL)
## Loading required package: DBI
library(getPass)
## Warning: package 'getPass' was built under R version 3.5.3
# set driver name
driver_name <- dbDriver(drvName = "PostgreSQL")

# establish database connection
db <- DBI::dbConnect(driver_name,
                     dbname = "sebi",
                     host = "192.168.0.12",
                     port = 5432,
                     user = "sebi",
                     password = getPass("Enter Password:")
)
## Please enter password in TK window (Alt+Tab)
# our query
sql_query_string <- "SELECT * FROM watchlist_data WHERE scrape_date = '2022-06-24';"

# combination of our connnection stuff and our query stuff
res <- dbSendQuery(db, sql_query_string)

# fetch our data query from the database and return a dataframe
data_pull <- dbFetch(res)

# clear our query results
dbClearResult(res)
## [1] TRUE
# politely disconnect from the database
dbDisconnect(db)
## [1] TRUE
source("payout_functions.R")
## 
## Attaching package: 'dplyr'
## The following objects are masked from 'package:stats':
## 
##     filter, lag
## The following objects are masked from 'package:base':
## 
##     intersect, setdiff, setequal, union
# create a mid price
data_pull$mid <- (data_pull$bid + data_pull$ask) / 2

# lets grab the QQQ Jan 20th 2023 calls
long_call_chain <- data_pull[data_pull$underlying_ticker == "QQQ" & data_pull$expiration_date == as.Date("2023-01-20"),]

# lets grab the QQQ July 27th calls
short_call_chain <- data_pull[data_pull$underlying_ticker == "QQQ" & data_pull$expiration_date == as.Date("2022-07-27"),]

long_call_strike <- 335

short_call_strike <- 335

sample_long <- long_call_profit(
  long_call_chain,
  long_call_strike
)

sample_short <- short_call_profit(
  short_call_chain,
  short_call_strike
)

# sample_pmcc <- call_diagonal_profit(
#   long_call_chain, 
#   long_call_strike,
#   short_call_chain,
#   short_call_strike
#   )

lineplot_profit(sample_long, "QQQ Long Jan 20th, 2023 Call")
## 
## Attaching package: 'plotly'
## The following object is masked from 'package:ggplot2':
## 
##     last_plot
## The following object is masked from 'package:stats':
## 
##     filter
## The following object is masked from 'package:graphics':
## 
##     layout
## Warning: package 'wesanderson' was built under R version 3.5.3
## Warning: `gather_()` was deprecated in tidyr 1.2.0.
## Please use `gather()` instead.
## This warning is displayed once every 8 hours.
## Call `lifecycle::last_lifecycle_warnings()` to see where this warning was generated.
## This version of bslib is designed to work with shiny version 1.6.0 or higher.
lineplot_profit(sample_short, "QQQ Short July 27th Call")
#lineplot_profit(sample_pmcc, "QQQ Long Jan 20th, 2023 Call\nShort July 27th Call")